package com.easipass.framework.eirframeworkjdbc;

import com.easipass.framework.eirframeworkjdbc.model.MessageLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@Component
public class MessageLogService {

    @Autowired
    MessageLogRepository messageLogRepository;

    public List<MessageLog> findByName(String name){
        return messageLogRepository.findByName(name);
    }

    public List<MessageLog> findByServiceName(String serviceName){
        return messageLogRepository.findByServiceName(serviceName);
    }

    public MessageLog save(String name,String serviceName,String appName,String content){
        MessageLog messageLog = new MessageLog();
        messageLog.setName(name);
        messageLog.setServiceName(serviceName);
        messageLog.setAppName(appName);
        messageLog.setContent(content);
        messageLog.setId(UUID.randomUUID().toString());
        messageLog.setCreateTime(LocalDateTime.now());
        return messageLogRepository.save(messageLog);
    }

    public MessageLogRepository getMessageLogRepository(){
        return this.messageLogRepository;
    }
}
